<?php
class Controller_Admin_User extends Controller_Admin_Layout {
	private $user_api;
	function __construct(Request $request, Response $response) {
        parent::__construct($request, $response);				
	}
	public function action_index($user_id = NULL)
	{
		$user_info = array();
		if ( ! is_null($user_id))
		{
			$user_info = Api::load('user')->read($user_id);
		}
		
		$user_list = Api::load('user')->get_all();

		$this->template->main = View::admin('user/page_user_list', array(
			'user_list' => $user_list,
			'user_info' => $user_info,
		));
	}

	/**
	 * tạo user mới
	 */
	public function action_create()
	{
		if (Request::current()->method() == 'POST')
		{
			if (! isset($_POST['username']))
			{
				$_POST['username'] = time();
			}
			$user = Api::load('user')->create($_POST);
			Flashmessage::getInstance()->doctrine($user);
		}

		$this->action_index();
	}

	/**
	 * edit 1 user đã có.
	 */
	 public function action_edit()
	 {
	 	
	 }


	/**
	 * Quản lý, thêm xóa role cho user
	 */
	public function action_role($user = NULL)
	{
		$this->auto_render = FALSE;
		$role_list = Api::load('role')->get_all();
		
		
		$this->response->body(View::admin('user/element_manager_role', array(
			'role_list' => $role_list,
		)));
		
	}
}